
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 07/26/2013 11:41:01
-- Generated from EDMX file: C:\Users\Ariel\Documents\Colegio de Medicos\Proyectos\Fiscalizacion\Fiscalizacion Final\AccesoDatos\Modelos\ModeloEntidades.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Colegio-de-medicos];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Habilitacion_Tramite_Matricula]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tramites_Matriculaciones] DROP CONSTRAINT [FK_Habilitacion_Tramite_Matricula];
GO
IF OBJECT_ID(N'[dbo].[FK_Localidad_Departamento]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Localidades] DROP CONSTRAINT [FK_Localidad_Departamento];
GO
IF OBJECT_ID(N'[dbo].[FK_EmpresaLocal]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Empresas] DROP CONSTRAINT [FK_EmpresaLocal];
GO
IF OBJECT_ID(N'[dbo].[FK_LugarLocalidad]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Lugares] DROP CONSTRAINT [FK_LugarLocalidad];
GO
IF OBJECT_ID(N'[dbo].[FK_PersonaLugar]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Personas] DROP CONSTRAINT [FK_PersonaLugar];
GO
IF OBJECT_ID(N'[dbo].[FK_titular_actual_Consultorio]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Empresas_Consultorio] DROP CONSTRAINT [FK_titular_actual_Consultorio];
GO
IF OBJECT_ID(N'[dbo].[FK_titulares_anteriores_en_Consultorio_Consultorio]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[titulares_anteriores_en_Consultorios] DROP CONSTRAINT [FK_titulares_anteriores_en_Consultorio_Consultorio];
GO
IF OBJECT_ID(N'[dbo].[FK_titulares_anteriores_en_Consultorio_Profesional]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[titulares_anteriores_en_Consultorios] DROP CONSTRAINT [FK_titulares_anteriores_en_Consultorio_Profesional];
GO
IF OBJECT_ID(N'[dbo].[FK_trabaja_en_consultorio_Consultorio]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[trabajan_en_consultorios] DROP CONSTRAINT [FK_trabaja_en_consultorio_Consultorio];
GO
IF OBJECT_ID(N'[dbo].[FK_trabaja_en_consultorio_Profesional]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[trabajan_en_consultorios] DROP CONSTRAINT [FK_trabaja_en_consultorio_Profesional];
GO
IF OBJECT_ID(N'[dbo].[FK_Tramite_Matriculacion_Consultorio]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tramites_Matriculaciones] DROP CONSTRAINT [FK_Tramite_Matriculacion_Consultorio];
GO
IF OBJECT_ID(N'[dbo].[FK_Titulo_Profecional_colegio_Titulo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Titulos_Profecionales_colegio] DROP CONSTRAINT [FK_Titulo_Profecional_colegio_Titulo];
GO
IF OBJECT_ID(N'[dbo].[FK_Titulo_Profecional_colegio_Profecional_colegio]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Titulos_Profecionales_colegio] DROP CONSTRAINT [FK_Titulo_Profecional_colegio_Profecional_colegio];
GO
IF OBJECT_ID(N'[dbo].[FK_Local_Propietario_Local]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Locales_Propietarios] DROP CONSTRAINT [FK_Local_Propietario_Local];
GO
IF OBJECT_ID(N'[dbo].[FK_Local_Propietario_Propietario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Locales_Propietarios] DROP CONSTRAINT [FK_Local_Propietario_Propietario];
GO
IF OBJECT_ID(N'[dbo].[FK_AdministradorTramite_Matriculacion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tramites_Matriculaciones] DROP CONSTRAINT [FK_AdministradorTramite_Matriculacion];
GO
IF OBJECT_ID(N'[dbo].[FK_Profesion_Profesional_otro_colegio]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Personas_Profesional_otro_colegio] DROP CONSTRAINT [FK_Profesion_Profesional_otro_colegio];
GO
IF OBJECT_ID(N'[dbo].[FK_Especialidad_Profecional_colegio_Especialidad]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Especialidades_Profecionales_colegio] DROP CONSTRAINT [FK_Especialidad_Profecional_colegio_Especialidad];
GO
IF OBJECT_ID(N'[dbo].[FK_Especialidad_Profecional_colegio_Profecional_colegio]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Especialidades_Profecionales_colegio] DROP CONSTRAINT [FK_Especialidad_Profecional_colegio_Profecional_colegio];
GO
IF OBJECT_ID(N'[dbo].[FK_Loguin_Administrador]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Personas_Administrador] DROP CONSTRAINT [FK_Loguin_Administrador];
GO
IF OBJECT_ID(N'[dbo].[FK_Inspector_Local]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Lugares_Local] DROP CONSTRAINT [FK_Inspector_Local];
GO
IF OBJECT_ID(N'[dbo].[FK_Pago_Tramite_Matriculacion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tramites_Matriculaciones] DROP CONSTRAINT [FK_Pago_Tramite_Matriculacion];
GO
IF OBJECT_ID(N'[dbo].[FK_Local_inherits_Lugar]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Lugares_Local] DROP CONSTRAINT [FK_Local_inherits_Lugar];
GO
IF OBJECT_ID(N'[dbo].[FK_Consultorio_inherits_Empresa]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Empresas_Consultorio] DROP CONSTRAINT [FK_Consultorio_inherits_Empresa];
GO
IF OBJECT_ID(N'[dbo].[FK_Profesional_inherits_Persona]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Personas_Profesional] DROP CONSTRAINT [FK_Profesional_inherits_Persona];
GO
IF OBJECT_ID(N'[dbo].[FK_Profecional_colegio_inherits_Profesional]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Personas_Profecional_colegio] DROP CONSTRAINT [FK_Profecional_colegio_inherits_Profesional];
GO
IF OBJECT_ID(N'[dbo].[FK_Propietario_inherits_Persona]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Personas_Propietario] DROP CONSTRAINT [FK_Propietario_inherits_Persona];
GO
IF OBJECT_ID(N'[dbo].[FK_Administrador_inherits_Persona]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Personas_Administrador] DROP CONSTRAINT [FK_Administrador_inherits_Persona];
GO
IF OBJECT_ID(N'[dbo].[FK_Profesional_otro_colegio_inherits_Profesional]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Personas_Profesional_otro_colegio] DROP CONSTRAINT [FK_Profesional_otro_colegio_inherits_Profesional];
GO
IF OBJECT_ID(N'[dbo].[FK_Inspector_inherits_Persona]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Personas_Inspector] DROP CONSTRAINT [FK_Inspector_inherits_Persona];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Tramites_Matriculaciones]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tramites_Matriculaciones];
GO
IF OBJECT_ID(N'[dbo].[Personas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Personas];
GO
IF OBJECT_ID(N'[dbo].[Habilitaciones]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Habilitaciones];
GO
IF OBJECT_ID(N'[dbo].[Especialidades]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Especialidades];
GO
IF OBJECT_ID(N'[dbo].[Localidades]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Localidades];
GO
IF OBJECT_ID(N'[dbo].[Departamentos]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Departamentos];
GO
IF OBJECT_ID(N'[dbo].[Empresas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Empresas];
GO
IF OBJECT_ID(N'[dbo].[Lugares]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Lugares];
GO
IF OBJECT_ID(N'[dbo].[Titulos]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Titulos];
GO
IF OBJECT_ID(N'[dbo].[Profesiones]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Profesiones];
GO
IF OBJECT_ID(N'[dbo].[Loguines]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Loguines];
GO
IF OBJECT_ID(N'[dbo].[Pagos]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Pagos];
GO
IF OBJECT_ID(N'[dbo].[Lugares_Local]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Lugares_Local];
GO
IF OBJECT_ID(N'[dbo].[Empresas_Consultorio]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Empresas_Consultorio];
GO
IF OBJECT_ID(N'[dbo].[Personas_Profesional]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Personas_Profesional];
GO
IF OBJECT_ID(N'[dbo].[Personas_Profecional_colegio]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Personas_Profecional_colegio];
GO
IF OBJECT_ID(N'[dbo].[Personas_Propietario]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Personas_Propietario];
GO
IF OBJECT_ID(N'[dbo].[Personas_Administrador]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Personas_Administrador];
GO
IF OBJECT_ID(N'[dbo].[Personas_Profesional_otro_colegio]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Personas_Profesional_otro_colegio];
GO
IF OBJECT_ID(N'[dbo].[Personas_Inspector]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Personas_Inspector];
GO
IF OBJECT_ID(N'[dbo].[titulares_anteriores_en_Consultorios]', 'U') IS NOT NULL
    DROP TABLE [dbo].[titulares_anteriores_en_Consultorios];
GO
IF OBJECT_ID(N'[dbo].[trabajan_en_consultorios]', 'U') IS NOT NULL
    DROP TABLE [dbo].[trabajan_en_consultorios];
GO
IF OBJECT_ID(N'[dbo].[Titulos_Profecionales_colegio]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Titulos_Profecionales_colegio];
GO
IF OBJECT_ID(N'[dbo].[Locales_Propietarios]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Locales_Propietarios];
GO
IF OBJECT_ID(N'[dbo].[Especialidades_Profecionales_colegio]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Especialidades_Profecionales_colegio];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Tramites_Matriculaciones'
CREATE TABLE [dbo].[Tramites_Matriculaciones] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [numero] nvarchar(max)  NULL,
    [fecha_inicio] datetime  NULL,
    [numero_acta] nvarchar(max)  NULL,
    [notas] nvarchar(max)  NULL,
    [lista_plantel_cerrada] bit  NOT NULL,
    [lista_plantel_cerrada_fecha] datetime  NULL,
    [eliminado] bit  NOT NULL,
    [Habilitacion_Id] int  NOT NULL,
    [Consultorio_Id] int  NOT NULL,
    [Administrador_Id] int  NOT NULL,
    [Pago_Id] int  NULL
);
GO

-- Creating table 'Personas'
CREATE TABLE [dbo].[Personas] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NULL,
    [apellido] nvarchar(max)  NULL,
    [dni] nvarchar(max)  NULL,
    [celular] nvarchar(max)  NULL,
    [eMail] nvarchar(max)  NULL,
    [eMail_auxiliar] nvarchar(max)  NULL,
    [vive_Id] int  NULL
);
GO

-- Creating table 'Habilitaciones'
CREATE TABLE [dbo].[Habilitaciones] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [numero_matricula_ministerio] nvarchar(max)  NULL,
    [fecha_habilitacion] datetime  NULL
);
GO

-- Creating table 'Especialidades'
CREATE TABLE [dbo].[Especialidades] (
    [Id] smallint IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NULL
);
GO

-- Creating table 'Localidades'
CREATE TABLE [dbo].[Localidades] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NULL,
    [codigo_postal] nvarchar(max)  NULL,
    [Departamento_Id] int  NULL
);
GO

-- Creating table 'Departamentos'
CREATE TABLE [dbo].[Departamentos] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NULL
);
GO

-- Creating table 'Empresas'
CREATE TABLE [dbo].[Empresas] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [cuit] nvarchar(max)  NULL,
    [razon_social] nvarchar(max)  NULL,
    [eMail] nvarchar(max)  NULL,
    [Local_Id] int  NOT NULL
);
GO

-- Creating table 'Lugares'
CREATE TABLE [dbo].[Lugares] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [domicilio] nvarchar(max)  NULL,
    [telefono] nvarchar(max)  NULL,
    [Localidad_Id] int  NULL
);
GO

-- Creating table 'Titulos'
CREATE TABLE [dbo].[Titulos] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [codigo] nvarchar(max)  NULL,
    [nombre] nvarchar(max)  NULL,
    [fecha] datetime  NULL
);
GO

-- Creating table 'Profesiones'
CREATE TABLE [dbo].[Profesiones] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NULL
);
GO

-- Creating table 'Loguines'
CREATE TABLE [dbo].[Loguines] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [officina] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Pagos'
CREATE TABLE [dbo].[Pagos] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [monto] decimal(18,0)  NULL,
    [forma_de_abono] nvarchar(max)  NULL
);
GO

-- Creating table 'Lugares_Local'
CREATE TABLE [dbo].[Lugares_Local] (
    [baño] bit  NULL,
    [plano_municipal] bit  NULL,
    [plano_contingencia] bit  NULL,
    [Id] int  NOT NULL,
    [Inspecciono_Id] int  NULL
);
GO

-- Creating table 'Empresas_Consultorio'
CREATE TABLE [dbo].[Empresas_Consultorio] (
    [Id] int  NOT NULL,
    [titular_actual_Id] int  NULL
);
GO

-- Creating table 'Personas_Profesional'
CREATE TABLE [dbo].[Personas_Profesional] (
    [certificado] bit  NULL,
    [fecha_incorporacion] datetime  NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'Personas_Profecional_colegio'
CREATE TABLE [dbo].[Personas_Profecional_colegio] (
    [matricula] nvarchar(max)  NULL,
    [cuota] bit  NULL,
    [codigo] nvarchar(max)  NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'Personas_Propietario'
CREATE TABLE [dbo].[Personas_Propietario] (
    [Id] int  NOT NULL
);
GO

-- Creating table 'Personas_Administrador'
CREATE TABLE [dbo].[Personas_Administrador] (
    [fecha_incorporacion] datetime  NULL,
    [usuario] nvarchar(max)  NOT NULL,
    [contraseña] nvarchar(max)  NOT NULL,
    [Id] int  NOT NULL,
    [Loguin_Id] int  NULL
);
GO

-- Creating table 'Personas_Profesional_otro_colegio'
CREATE TABLE [dbo].[Personas_Profesional_otro_colegio] (
    [numero] nvarchar(max)  NULL,
    [local_aprobado] bit  NOT NULL,
    [Id] int  NOT NULL,
    [Profesion_Id] int  NULL
);
GO

-- Creating table 'Personas_Inspector'
CREATE TABLE [dbo].[Personas_Inspector] (
    [Id] int  NOT NULL
);
GO

-- Creating table 'titulares_anteriores_en_Consultorios'
CREATE TABLE [dbo].[titulares_anteriores_en_Consultorios] (
    [titular_anterior_en_consultorio_Id] int  NOT NULL,
    [titulares_anteriores_Id] int  NOT NULL
);
GO

-- Creating table 'trabajan_en_consultorios'
CREATE TABLE [dbo].[trabajan_en_consultorios] (
    [trabaja_en_Consultorio_Id] int  NOT NULL,
    [plantel_profesional_Id] int  NOT NULL
);
GO

-- Creating table 'Titulos_Profecionales_colegio'
CREATE TABLE [dbo].[Titulos_Profecionales_colegio] (
    [Titulos_Id] int  NOT NULL,
    [Profecionales_colegio_Id] int  NOT NULL
);
GO

-- Creating table 'Locales_Propietarios'
CREATE TABLE [dbo].[Locales_Propietarios] (
    [Locales_Id] int  NOT NULL,
    [Propietarios_Id] int  NOT NULL
);
GO

-- Creating table 'Especialidades_Profecionales_colegio'
CREATE TABLE [dbo].[Especialidades_Profecionales_colegio] (
    [Especialidad_Id] smallint  NOT NULL,
    [Profecional_colegio_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Tramites_Matriculaciones'
ALTER TABLE [dbo].[Tramites_Matriculaciones]
ADD CONSTRAINT [PK_Tramites_Matriculaciones]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Personas'
ALTER TABLE [dbo].[Personas]
ADD CONSTRAINT [PK_Personas]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Habilitaciones'
ALTER TABLE [dbo].[Habilitaciones]
ADD CONSTRAINT [PK_Habilitaciones]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Especialidades'
ALTER TABLE [dbo].[Especialidades]
ADD CONSTRAINT [PK_Especialidades]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Localidades'
ALTER TABLE [dbo].[Localidades]
ADD CONSTRAINT [PK_Localidades]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Departamentos'
ALTER TABLE [dbo].[Departamentos]
ADD CONSTRAINT [PK_Departamentos]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Empresas'
ALTER TABLE [dbo].[Empresas]
ADD CONSTRAINT [PK_Empresas]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Lugares'
ALTER TABLE [dbo].[Lugares]
ADD CONSTRAINT [PK_Lugares]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Titulos'
ALTER TABLE [dbo].[Titulos]
ADD CONSTRAINT [PK_Titulos]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Profesiones'
ALTER TABLE [dbo].[Profesiones]
ADD CONSTRAINT [PK_Profesiones]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Loguines'
ALTER TABLE [dbo].[Loguines]
ADD CONSTRAINT [PK_Loguines]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Pagos'
ALTER TABLE [dbo].[Pagos]
ADD CONSTRAINT [PK_Pagos]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Lugares_Local'
ALTER TABLE [dbo].[Lugares_Local]
ADD CONSTRAINT [PK_Lugares_Local]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Empresas_Consultorio'
ALTER TABLE [dbo].[Empresas_Consultorio]
ADD CONSTRAINT [PK_Empresas_Consultorio]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Personas_Profesional'
ALTER TABLE [dbo].[Personas_Profesional]
ADD CONSTRAINT [PK_Personas_Profesional]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Personas_Profecional_colegio'
ALTER TABLE [dbo].[Personas_Profecional_colegio]
ADD CONSTRAINT [PK_Personas_Profecional_colegio]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Personas_Propietario'
ALTER TABLE [dbo].[Personas_Propietario]
ADD CONSTRAINT [PK_Personas_Propietario]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Personas_Administrador'
ALTER TABLE [dbo].[Personas_Administrador]
ADD CONSTRAINT [PK_Personas_Administrador]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Personas_Profesional_otro_colegio'
ALTER TABLE [dbo].[Personas_Profesional_otro_colegio]
ADD CONSTRAINT [PK_Personas_Profesional_otro_colegio]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Personas_Inspector'
ALTER TABLE [dbo].[Personas_Inspector]
ADD CONSTRAINT [PK_Personas_Inspector]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [titular_anterior_en_consultorio_Id], [titulares_anteriores_Id] in table 'titulares_anteriores_en_Consultorios'
ALTER TABLE [dbo].[titulares_anteriores_en_Consultorios]
ADD CONSTRAINT [PK_titulares_anteriores_en_Consultorios]
    PRIMARY KEY NONCLUSTERED ([titular_anterior_en_consultorio_Id], [titulares_anteriores_Id] ASC);
GO

-- Creating primary key on [trabaja_en_Consultorio_Id], [plantel_profesional_Id] in table 'trabajan_en_consultorios'
ALTER TABLE [dbo].[trabajan_en_consultorios]
ADD CONSTRAINT [PK_trabajan_en_consultorios]
    PRIMARY KEY NONCLUSTERED ([trabaja_en_Consultorio_Id], [plantel_profesional_Id] ASC);
GO

-- Creating primary key on [Titulos_Id], [Profecionales_colegio_Id] in table 'Titulos_Profecionales_colegio'
ALTER TABLE [dbo].[Titulos_Profecionales_colegio]
ADD CONSTRAINT [PK_Titulos_Profecionales_colegio]
    PRIMARY KEY NONCLUSTERED ([Titulos_Id], [Profecionales_colegio_Id] ASC);
GO

-- Creating primary key on [Locales_Id], [Propietarios_Id] in table 'Locales_Propietarios'
ALTER TABLE [dbo].[Locales_Propietarios]
ADD CONSTRAINT [PK_Locales_Propietarios]
    PRIMARY KEY NONCLUSTERED ([Locales_Id], [Propietarios_Id] ASC);
GO

-- Creating primary key on [Especialidad_Id], [Profecional_colegio_Id] in table 'Especialidades_Profecionales_colegio'
ALTER TABLE [dbo].[Especialidades_Profecionales_colegio]
ADD CONSTRAINT [PK_Especialidades_Profecionales_colegio]
    PRIMARY KEY NONCLUSTERED ([Especialidad_Id], [Profecional_colegio_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Habilitacion_Id] in table 'Tramites_Matriculaciones'
ALTER TABLE [dbo].[Tramites_Matriculaciones]
ADD CONSTRAINT [FK_Habilitacion_Tramite_Matricula]
    FOREIGN KEY ([Habilitacion_Id])
    REFERENCES [dbo].[Habilitaciones]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Habilitacion_Tramite_Matricula'
CREATE INDEX [IX_FK_Habilitacion_Tramite_Matricula]
ON [dbo].[Tramites_Matriculaciones]
    ([Habilitacion_Id]);
GO

-- Creating foreign key on [Departamento_Id] in table 'Localidades'
ALTER TABLE [dbo].[Localidades]
ADD CONSTRAINT [FK_Localidad_Departamento]
    FOREIGN KEY ([Departamento_Id])
    REFERENCES [dbo].[Departamentos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Localidad_Departamento'
CREATE INDEX [IX_FK_Localidad_Departamento]
ON [dbo].[Localidades]
    ([Departamento_Id]);
GO

-- Creating foreign key on [Local_Id] in table 'Empresas'
ALTER TABLE [dbo].[Empresas]
ADD CONSTRAINT [FK_EmpresaLocal]
    FOREIGN KEY ([Local_Id])
    REFERENCES [dbo].[Lugares_Local]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EmpresaLocal'
CREATE INDEX [IX_FK_EmpresaLocal]
ON [dbo].[Empresas]
    ([Local_Id]);
GO

-- Creating foreign key on [Localidad_Id] in table 'Lugares'
ALTER TABLE [dbo].[Lugares]
ADD CONSTRAINT [FK_LugarLocalidad]
    FOREIGN KEY ([Localidad_Id])
    REFERENCES [dbo].[Localidades]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_LugarLocalidad'
CREATE INDEX [IX_FK_LugarLocalidad]
ON [dbo].[Lugares]
    ([Localidad_Id]);
GO

-- Creating foreign key on [vive_Id] in table 'Personas'
ALTER TABLE [dbo].[Personas]
ADD CONSTRAINT [FK_PersonaLugar]
    FOREIGN KEY ([vive_Id])
    REFERENCES [dbo].[Lugares]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PersonaLugar'
CREATE INDEX [IX_FK_PersonaLugar]
ON [dbo].[Personas]
    ([vive_Id]);
GO

-- Creating foreign key on [titular_actual_Id] in table 'Empresas_Consultorio'
ALTER TABLE [dbo].[Empresas_Consultorio]
ADD CONSTRAINT [FK_titular_actual_Consultorio]
    FOREIGN KEY ([titular_actual_Id])
    REFERENCES [dbo].[Personas_Profesional]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_titular_actual_Consultorio'
CREATE INDEX [IX_FK_titular_actual_Consultorio]
ON [dbo].[Empresas_Consultorio]
    ([titular_actual_Id]);
GO

-- Creating foreign key on [titular_anterior_en_consultorio_Id] in table 'titulares_anteriores_en_Consultorios'
ALTER TABLE [dbo].[titulares_anteriores_en_Consultorios]
ADD CONSTRAINT [FK_titulares_anteriores_en_Consultorio_Consultorio]
    FOREIGN KEY ([titular_anterior_en_consultorio_Id])
    REFERENCES [dbo].[Empresas_Consultorio]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [titulares_anteriores_Id] in table 'titulares_anteriores_en_Consultorios'
ALTER TABLE [dbo].[titulares_anteriores_en_Consultorios]
ADD CONSTRAINT [FK_titulares_anteriores_en_Consultorio_Profesional]
    FOREIGN KEY ([titulares_anteriores_Id])
    REFERENCES [dbo].[Personas_Profesional]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_titulares_anteriores_en_Consultorio_Profesional'
CREATE INDEX [IX_FK_titulares_anteriores_en_Consultorio_Profesional]
ON [dbo].[titulares_anteriores_en_Consultorios]
    ([titulares_anteriores_Id]);
GO

-- Creating foreign key on [trabaja_en_Consultorio_Id] in table 'trabajan_en_consultorios'
ALTER TABLE [dbo].[trabajan_en_consultorios]
ADD CONSTRAINT [FK_trabaja_en_consultorio_Consultorio]
    FOREIGN KEY ([trabaja_en_Consultorio_Id])
    REFERENCES [dbo].[Empresas_Consultorio]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [plantel_profesional_Id] in table 'trabajan_en_consultorios'
ALTER TABLE [dbo].[trabajan_en_consultorios]
ADD CONSTRAINT [FK_trabaja_en_consultorio_Profesional]
    FOREIGN KEY ([plantel_profesional_Id])
    REFERENCES [dbo].[Personas_Profesional]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_trabaja_en_consultorio_Profesional'
CREATE INDEX [IX_FK_trabaja_en_consultorio_Profesional]
ON [dbo].[trabajan_en_consultorios]
    ([plantel_profesional_Id]);
GO

-- Creating foreign key on [Consultorio_Id] in table 'Tramites_Matriculaciones'
ALTER TABLE [dbo].[Tramites_Matriculaciones]
ADD CONSTRAINT [FK_Tramite_Matriculacion_Consultorio]
    FOREIGN KEY ([Consultorio_Id])
    REFERENCES [dbo].[Empresas_Consultorio]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Tramite_Matriculacion_Consultorio'
CREATE INDEX [IX_FK_Tramite_Matriculacion_Consultorio]
ON [dbo].[Tramites_Matriculaciones]
    ([Consultorio_Id]);
GO

-- Creating foreign key on [Titulos_Id] in table 'Titulos_Profecionales_colegio'
ALTER TABLE [dbo].[Titulos_Profecionales_colegio]
ADD CONSTRAINT [FK_Titulo_Profecional_colegio_Titulo]
    FOREIGN KEY ([Titulos_Id])
    REFERENCES [dbo].[Titulos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Profecionales_colegio_Id] in table 'Titulos_Profecionales_colegio'
ALTER TABLE [dbo].[Titulos_Profecionales_colegio]
ADD CONSTRAINT [FK_Titulo_Profecional_colegio_Profecional_colegio]
    FOREIGN KEY ([Profecionales_colegio_Id])
    REFERENCES [dbo].[Personas_Profecional_colegio]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Titulo_Profecional_colegio_Profecional_colegio'
CREATE INDEX [IX_FK_Titulo_Profecional_colegio_Profecional_colegio]
ON [dbo].[Titulos_Profecionales_colegio]
    ([Profecionales_colegio_Id]);
GO

-- Creating foreign key on [Locales_Id] in table 'Locales_Propietarios'
ALTER TABLE [dbo].[Locales_Propietarios]
ADD CONSTRAINT [FK_Local_Propietario_Local]
    FOREIGN KEY ([Locales_Id])
    REFERENCES [dbo].[Lugares_Local]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Propietarios_Id] in table 'Locales_Propietarios'
ALTER TABLE [dbo].[Locales_Propietarios]
ADD CONSTRAINT [FK_Local_Propietario_Propietario]
    FOREIGN KEY ([Propietarios_Id])
    REFERENCES [dbo].[Personas_Propietario]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Local_Propietario_Propietario'
CREATE INDEX [IX_FK_Local_Propietario_Propietario]
ON [dbo].[Locales_Propietarios]
    ([Propietarios_Id]);
GO

-- Creating foreign key on [Administrador_Id] in table 'Tramites_Matriculaciones'
ALTER TABLE [dbo].[Tramites_Matriculaciones]
ADD CONSTRAINT [FK_AdministradorTramite_Matriculacion]
    FOREIGN KEY ([Administrador_Id])
    REFERENCES [dbo].[Personas_Administrador]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AdministradorTramite_Matriculacion'
CREATE INDEX [IX_FK_AdministradorTramite_Matriculacion]
ON [dbo].[Tramites_Matriculaciones]
    ([Administrador_Id]);
GO

-- Creating foreign key on [Profesion_Id] in table 'Personas_Profesional_otro_colegio'
ALTER TABLE [dbo].[Personas_Profesional_otro_colegio]
ADD CONSTRAINT [FK_Profesion_Profesional_otro_colegio]
    FOREIGN KEY ([Profesion_Id])
    REFERENCES [dbo].[Profesiones]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Profesion_Profesional_otro_colegio'
CREATE INDEX [IX_FK_Profesion_Profesional_otro_colegio]
ON [dbo].[Personas_Profesional_otro_colegio]
    ([Profesion_Id]);
GO

-- Creating foreign key on [Especialidad_Id] in table 'Especialidades_Profecionales_colegio'
ALTER TABLE [dbo].[Especialidades_Profecionales_colegio]
ADD CONSTRAINT [FK_Especialidad_Profecional_colegio_Especialidad]
    FOREIGN KEY ([Especialidad_Id])
    REFERENCES [dbo].[Especialidades]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Profecional_colegio_Id] in table 'Especialidades_Profecionales_colegio'
ALTER TABLE [dbo].[Especialidades_Profecionales_colegio]
ADD CONSTRAINT [FK_Especialidad_Profecional_colegio_Profecional_colegio]
    FOREIGN KEY ([Profecional_colegio_Id])
    REFERENCES [dbo].[Personas_Profecional_colegio]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Especialidad_Profecional_colegio_Profecional_colegio'
CREATE INDEX [IX_FK_Especialidad_Profecional_colegio_Profecional_colegio]
ON [dbo].[Especialidades_Profecionales_colegio]
    ([Profecional_colegio_Id]);
GO

-- Creating foreign key on [Loguin_Id] in table 'Personas_Administrador'
ALTER TABLE [dbo].[Personas_Administrador]
ADD CONSTRAINT [FK_Loguin_Administrador]
    FOREIGN KEY ([Loguin_Id])
    REFERENCES [dbo].[Loguines]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Loguin_Administrador'
CREATE INDEX [IX_FK_Loguin_Administrador]
ON [dbo].[Personas_Administrador]
    ([Loguin_Id]);
GO

-- Creating foreign key on [Inspecciono_Id] in table 'Lugares_Local'
ALTER TABLE [dbo].[Lugares_Local]
ADD CONSTRAINT [FK_Inspector_Local]
    FOREIGN KEY ([Inspecciono_Id])
    REFERENCES [dbo].[Personas_Inspector]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Inspector_Local'
CREATE INDEX [IX_FK_Inspector_Local]
ON [dbo].[Lugares_Local]
    ([Inspecciono_Id]);
GO

-- Creating foreign key on [Pago_Id] in table 'Tramites_Matriculaciones'
ALTER TABLE [dbo].[Tramites_Matriculaciones]
ADD CONSTRAINT [FK_Pago_Tramite_Matriculacion]
    FOREIGN KEY ([Pago_Id])
    REFERENCES [dbo].[Pagos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Pago_Tramite_Matriculacion'
CREATE INDEX [IX_FK_Pago_Tramite_Matriculacion]
ON [dbo].[Tramites_Matriculaciones]
    ([Pago_Id]);
GO

-- Creating foreign key on [Id] in table 'Lugares_Local'
ALTER TABLE [dbo].[Lugares_Local]
ADD CONSTRAINT [FK_Local_inherits_Lugar]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Lugares]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Empresas_Consultorio'
ALTER TABLE [dbo].[Empresas_Consultorio]
ADD CONSTRAINT [FK_Consultorio_inherits_Empresa]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Empresas]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Personas_Profesional'
ALTER TABLE [dbo].[Personas_Profesional]
ADD CONSTRAINT [FK_Profesional_inherits_Persona]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Personas]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Personas_Profecional_colegio'
ALTER TABLE [dbo].[Personas_Profecional_colegio]
ADD CONSTRAINT [FK_Profecional_colegio_inherits_Profesional]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Personas_Profesional]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Personas_Propietario'
ALTER TABLE [dbo].[Personas_Propietario]
ADD CONSTRAINT [FK_Propietario_inherits_Persona]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Personas]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Personas_Administrador'
ALTER TABLE [dbo].[Personas_Administrador]
ADD CONSTRAINT [FK_Administrador_inherits_Persona]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Personas]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Personas_Profesional_otro_colegio'
ALTER TABLE [dbo].[Personas_Profesional_otro_colegio]
ADD CONSTRAINT [FK_Profesional_otro_colegio_inherits_Profesional]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Personas_Profesional]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Personas_Inspector'
ALTER TABLE [dbo].[Personas_Inspector]
ADD CONSTRAINT [FK_Inspector_inherits_Persona]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Personas]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------